import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/hj_model/video_model.dart';
import 'package:tiktokadult/hj_utils/api_service/mine_service.dart';
import 'package:tiktokadult/hj_utils/screen.dart';
import 'package:tiktokadult/routers/jump_router.dart';
import 'package:tiktokadult/tools_base/global_store/store.dart';
import 'package:tiktokadult/tools_base/loading/loading_alert_widget.dart';
import 'package:tiktokadult/tools_base/net/base_resp_bean.dart';

class PostDetailCoinDialog extends StatelessWidget {
  final Function? leftCallback;
  final VideoModel? model;

  const PostDetailCoinDialog({Key? key, this.leftCallback, this.model}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.transparent,
        body: GestureDetector(
          child: Container(
            width: screen.screenWidth,
            height: screen.screenHeight,
            color: Color.fromRGBO(14, 20, 30, 0.6),
            child: Center(
                child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                InkWell(
                  onTap: () async {
                    if (leftCallback != null) {
                      leftCallback?.call();
                      return;
                    }

                    LoadingAlertWidget.show();
                    BaseRespBean data = await MineService.postBuyVideo(model?.id, 1);
                    LoadingAlertWidget.cancel();
                    if (data.isSuccess) {
                      globalStore.updateUserInfo();

                      Get.back(result: true);
                    } else {
                      if (data.code == 8000) {
                        jumpToWalletPage(tabPosition: 1);
                      }
                      // else {
                      //   showToast("网络异常, 支付失败");
                      // }
                    }
                  },
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(30)),
                      gradient: LinearGradient(
                        colors: [
                          Color.fromRGBO(255, 238, 220, 1),
                          Color.fromRGBO(249, 219, 191, 1),
                        ],
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                      ),
                    ),
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Image.asset(
                          "post_detail_coin.png".communityPath,
                          width: 30,
                          height: 30,
                        ),
                        Text(
                          "${model?.videoCoin() ?? 0}金币解锁继续",
                          style: TextStyle(
                            color: Color(0xff370000),
                            fontSize: 14,
                            fontWeight: FontWeight.w400,
                            fontStyle: FontStyle.normal,
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            )),
          ),
          onTap: () async {
            Get.back();
          },
        ));
  }
}
